<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
    mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Page],
    components: {
        ShareQrcodeBox: async () =>
            Vue.extend(
                await Vue.prototype.$vFN.Components.Base.ShareQrcodeBox()
            ),
    },
    data() {
        return {
            appWindow: window,

            webUrl: this.$vFN.Tools.getShopLocationUrl(),
            type: 1, //类型 1今日 2昨日 3七天

            manageInfo: null, //经营概要数据
            loginInfo: null, //登录信息

            hotGoodsList: [], //热销商品列表

            miniappCodeUrl: null,
            miniappCodeErrorMessage: "",
            miniappCodeLoad: false,

            isLoading: false,
        };
    },
    methods: {
        showCode() {
            this.$refs.shareQrcodeBoxHome.init();
        },
        // 获取经营概要数据
        async getManageInfo() {
            this.isLoading = true;
            let res = await this.$vFN.Http.post(
                {
                    url: "mall-site-portal/portal-login/getBusinessOverview",
                    data: {
                        type: this.type,
                    },
                },
                window
            );
            this.isLoading = false;
            if (res._ok) {
                this.manageInfo = res.data;
            }
        },

        // 获取登录的数据
        async getLoginInfo() {
            let res = await this.$vFN.Http.post(
                {
                    url: "mall-site-portal/portal-login/info",
                },
                window
            );

            if (res._ok) {
                this.loginInfo = res.data;
            }
        },

        // 获取小程序二维码
        async getMiniAppCode() {
            if (
                this.miniappCodeUrl ||
                this.miniappCodeErrorMessage ||
                this.miniappCodeLoad
            ) {
                return;
            }
            this.miniappCodeLoad = true;
            let res = await this.$vFN.Tools.getWxAppShareCode();
            console.error(222, res);
            if (res) {
                this.miniappCodeUrl = res;
            } else {
                this.miniappCodeErrorMessage = res.message;
            }
            this.miniappCodeLoad = false;
        },

        async getHot() {
            let res = await this.$vFN.Http.post(
                {
                    url: "mall-site-portal/portal-login/getHotProduct",
                    data: {
                        productCount: 30,
                    },
                },
                window
            );

            if (res._ok) {
                this.hotGoodsList = res.data;
            }
        },

        toSetMiniapp() {
            this.$router.push(
                this.$vFN.Tools.toUrl({
                    path: "/channel/wxapp/manage",
                })
            );
        },

        init() {
            this.getLoginInfo();
            this.getManageInfo();
            this.getHot();
        },
    },
    mounted() {
        this.init();
        this.$nextTick(function () {});
    },
    activated() {},
};
</script>



